﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;

namespace AI3SaveEditor
{
    public sealed class DecryptUtil
    {
        public static string DecryptFile(string file) {
            if (Path.GetExtension(file) != ".pp")
                throw new ApplicationException("不支持的文件格式");
            string decryptExe = Path.Combine(Application.StartupPath, "AG3Decrypt_to_AG3Demo.exe");
            Process process = new Process();
            process.StartInfo = new ProcessStartInfo(decryptExe, file);
            process.Start();
            process.WaitForExit();
            return Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file));
        }

        public static string DecryptDir(string dir) {
            if (!Directory.Exists(dir))
                throw new ApplicationException("文件夹不存在");
            string decryptExe = Path.Combine(Application.StartupPath, "AG3Decrypt_to_AG3Demo.exe");
            Process process = new Process();
            process.StartInfo = new ProcessStartInfo(decryptExe, dir);
            process.Start();
            process.WaitForExit();
            return dir + ".pp";
        }
    }
}
